home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
BARNET
/
COMPILER
/
SATHER
/
!Sather
/
Library
/
Containrs
/
sa
/
member
< prev
next >
Wrap
Text File
|
1996-06-01
|
3KB
|
84 lines
---------------------------> Sather 1.1 source file <--------------------------
-- membership.sa: Membership functions
-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
-- Copyright (C) 1995, International Computer Science Institute
-- $Id: member.sa,v 1.3 1996/06/01 21:36:29 gomes Exp $
--
-- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
-- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
-- LICENSE contained in the file: Sather/Doc/License of the
-- Sather distribution. The license is also available from ICSI,
-- 1947 Center St., Suite 600, Berkeley CA 94704, USA.
-------------------------------------------------------------------
class MEMBER{ETP,ATP<$CONTAINER{ETP}} is
-- Various membership functions on containers
private include COMPARE{ETP};
find_if(a: ATP,test:ROUT{ETP}:BOOL):ETP is
-- Use inout
-- Return leftmost element of self which satisfies `test',
-- or void if there is none. Self may be void.
loop r ::= a.elt!; if test.call(r) then return r end; end;
return void
end;
count_if(a: ATP,test:ROUT{ETP}:BOOL):INT is
-- The number of elements which satisfy `test'.
-- Self may be void.
r::=0;
loop if test.call(a.elt!) then r:=r+1 end end;
return r
end;
count(a: ATP,v:ETP):INT is
-- The number of elements that are `elt_eq' to `v'.
-- Self may be void.
r::=0;
loop if elt_eq(a.elt!,v) then r:=r+1 end end;
return r
end;
some(a: ATP,test:ROUT{ETP}:BOOL):BOOL is
-- True if some element of self satisfies `test'.
-- Self may be void.
loop if test.call(a.elt!) then return true end end;
return false
end;
every(a: ATP,test:ROUT{ETP}:BOOL):BOOL is
-- True if every element of self satisfies `test'.
-- Self may be void.
loop if ~test.call(a.elt!) then return false end end;
return true
end;
notany(a: ATP,test:ROUT{ETP}:BOOL):BOOL is
-- True if none of the elements of self satisfies `test'.
-- Self may be void.
loop if test.call(a.elt!) then return false end end;
return true
end;
notevery(a: ATP,test:ROUT{ETP}:BOOL):BOOL is
-- True if not every element of self satisfies `test'.
-- Self may be void.
loop if ~test.call(a.elt!) then return true end end;
return false
end;
filter!(once a: ATP,once f:ROUT{ETP}:BOOL): ETP pre ~void(a) is
loop
e ::= a.elt!;
if f.call(e) then yield e end
end
end;
filter_not!(once a: ATP,once f:ROUT{ETP}:BOOL): ETP pre ~void(a) is
loop e ::= a.elt!; if ~f.call(e) then yield e end end
end;
end; -- class MEMBER{ETP,ATP<$CONTAINER{ETP}}
-------------------------------------------------------------------